Programming Languages Section

PowerShell

Card image
Post by Amina Delali, September 20th,2021

Some Facts

PowerShell is a scripting language combined with a command-line shell. It is built on the Microsoft .Net Framework, and used at first to automate the administration of the Windows operating system using the command-line shell. It’s core is now open source and cross-platform, so it allows task automation and configuration management in different operating systems: Windows, Linux, and MacOS.

It is a modern command shell that has more advanced functionalities than a command prompt. It is object oriented, and accepts and returns .NET objects. Its commands are called cmdlet, and the language is very easy to learn and to implement.



How to install it

  • on Windows:

    Usually, PowerShell is already installed on Windows 10. If it is not the case, you can install it following the steps below:

    1. go to this  github releases page. Then go to the assets section, and select the msi file corresponding to your system: for example PowerShell-7.1.4-win-x64.msi for the 64 bit version (the latest version available at the time of writing this post) .
    2. run the installer and follow the instructions.
    3. launch PowerShell from the start menu.

    For more details about the installation, you can check the following link.

  • on Ubuntu :

    To install PowerShell on Ubuntu, just follow the steps below:

    1. open the terminal, then run the following command: sudo snap install --classic powershell
    2. to check the installed PowerShell version, just run the following command: pwsh --version

In the video below, the details of the installation of the PowerShelllanguage on Ubuntu.

The Hello World Example

To test your first PowerShell Hello World code on Ubuntu, just do the following:

  1. create the “Hello.ps1” file and save it into the Home folder.
  2. in the previously created file, write and save the following code:
    Write-Host "Hello World!"
  3. to run your code, open the terminal, and run the following command: pswh Hello.ps1

For more details about this code, you can check these pages: page1 and page2.



Something to say ?

If you want to add something about the PowerShell language or about this post, please feel free to do it by commenting below 🙂 .